package com.ruoyi.honors.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.honors.domain.JwTeachHonors;
import com.ruoyi.honors.service.IJwTeachHonorsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学院荣誉Controller
 * 
 * @author ruoyi
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/honors/honors")
public class JwTeachHonorsController extends BaseController
{
    @Autowired
    private IJwTeachHonorsService jwTeachHonorsService;

    /**
     * 查询学院荣誉列表
     */
    @PreAuthorize("@ss.hasPermi('honors:honors:list')")
    @GetMapping("/list")
    public TableDataInfo list(JwTeachHonors jwTeachHonors)
    {
        startPage();
        List<JwTeachHonors> list = jwTeachHonorsService.selectJwTeachHonorsList(jwTeachHonors);
        return getDataTable(list);
    }

    /**
     * 导出学院荣誉列表
     */
    @PreAuthorize("@ss.hasPermi('honors:honors:export')")
    @Log(title = "学院荣誉", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JwTeachHonors jwTeachHonors)
    {
        List<JwTeachHonors> list = jwTeachHonorsService.selectJwTeachHonorsList(jwTeachHonors);
        ExcelUtil<JwTeachHonors> util = new ExcelUtil<JwTeachHonors>(JwTeachHonors.class);
        util.exportExcel(response, list, "学院荣誉数据");
    }

    /**
     * 获取学院荣誉详细信息
     */
    @PreAuthorize("@ss.hasPermi('honors:honors:query')")
    @GetMapping(value = "/{thId}")
    public AjaxResult getInfo(@PathVariable("thId") Long thId)
    {
        return success(jwTeachHonorsService.selectJwTeachHonorsByThId(thId));
    }

    /**
     * 新增学院荣誉
     */
    @PreAuthorize("@ss.hasPermi('honors:honors:add')")
    @Log(title = "学院荣誉", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JwTeachHonors jwTeachHonors)
    {
        SysUser user= SecurityUtils.getLoginUser().getUser();
        jwTeachHonors.setDeptId(104L);
        jwTeachHonors.setUserId(user.getUserId());
        return toAjax(jwTeachHonorsService.insertJwTeachHonors(jwTeachHonors));
    }

    /**
     * 修改学院荣誉
     */
    @PreAuthorize("@ss.hasPermi('honors:honors:edit')")
    @Log(title = "学院荣誉", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JwTeachHonors jwTeachHonors)
    {
        return toAjax(jwTeachHonorsService.updateJwTeachHonors(jwTeachHonors));
    }

    /**
     * 删除学院荣誉
     */
    @PreAuthorize("@ss.hasPermi('honors:honors:remove')")
    @Log(title = "学院荣誉", businessType = BusinessType.DELETE)
	@DeleteMapping("/{thIds}")
    public AjaxResult remove(@PathVariable Long[] thIds)
    {
        return toAjax(jwTeachHonorsService.deleteJwTeachHonorsByThIds(thIds));
    }
}
